<?php
/**
*btc列表
*/
require_once 'common.inc.php';

require_once MCC_ROOT.'/useroperation.inc.php';
$matches=parse_url($_SERVER['HTTP_REFERER']);

$userarray=array('username','realname','tentqq','email','password');

//$url=$matches['scheme'].'://'.$matches['host'].'/';
//!in_array('0',$larr)&&adminmsg('你没有被赋予操作该项的权限！');'7'=>'btchina','8'=>'xunlei',
$warray=array('0'=>'未知','1'=>'btzero','2'=>'cngba','3'=>'cnxp','4'=>'ydy','5'=>'fr','6'=>'btcool','9'=>'其他');
error_reporting(0);
if('show'==$action)
{
	//计算出BCT列表
	$sql="select * from area order by btcid";
	$query=$dsid->query($sql);
	$btcstr ="";
	$lnum =array();
	$ip=array();
	while($result=$dsid->fetch_array($query))
	{	
		$lnum[]=$result['btcid'];
		$ip[]=$result['describe'].":".$result['port'];
		$btcstr .="<option value=\"".$result['btcid']."\">".$result['btcid']."</option>";
		
		//echo "<br>{$lnum[ip]}";
	}
	//echo "<pre>";
	//print_r($ip);
	//计算出总的种子数目
	$countnum=0;
	$list = array();
	for($k=0;$k<count($lnum);$k++)
	{
		$btcsql="select count(*) as btcnum from localhash_1 where btcid = '".$lnum[$k]."'";
		$btcquery=$dsid->query($btcsql);
		$btccount = $dsid->result($btcquery,0);
		$countnum+=$btccount;
		//print "当前ASC号：{$lnum[$k]}种子数目为：{$btccount}";
		$btclist[][btcid] = $btccount;
		//$btclistc[][ip] = $lnum['ip'];
		//print_r($lnum[$k]['ip']);
	}
	for($k=0;$k<count($lnum);$k++)
	{
		$btcsql="select count(*) as btcnum from localhash_1 where btcid = '".$lnum[$k]."' and completed='1'";
		$btcquery=$dsid->query($btcsql);
		$btccount = $dsid->result($btcquery,0);
		$countnumc+=$btccount;
		//print "当前ASC号：{$lnum[$k]}种子数目为：{$btccount}";
		$btclistc[] = $btccount;
		
	}
	for($i=0;$i<count($btclist);$i++){
		$btclist[$i][completed]=$btclistc[$i];
	}
	$btclist_sum = $countnum;
	$btclistc_sum = $countnumc;
	//echo "当前总数目为：{$countnum}";

    include_once MCC_ROOT.'/templates/msystem/count.htm';
}
if('search'==$action)
{
	/*if(empty($page))
	{
		$stime=GmtToUnix($stime);
		$etime=GmtToUnix($etime);
	}*/
	
	$sql="select * from area order by btcid";
	$query=$dsid->query($sql);
	$btcstr ="";
	$lnum =array();
	while($result=$dsid->fetch_array($query))
	{	
		$lnum[]=$result['btcid'];
		$btcstr .="<option value=\"".$result['btcid']."\">".$result['btcid']."</option>";
	}

	
	if($stime>$etime)
		adminmsg('时间参数错误','count.inc.php?action=show');	
	else
	{	
	//IP来源
		$cnum=array();//查询数据结果
		
		$limit=30;
		$page=intval($page)<1?1:intval($page);
		$start=(intval($page)-1)*$limit;
	
		$stimeo=$stime;
		$etimeo=$etime;
		if(!ereg("-",$stimeo))$stimeo=date('Y-m-d',$stimeo);
		if(!ereg("-",$etimeo))$etimeo=date('Y-m-d',$etimeo);
		
		$where='';
		$strstr="全部ACS";
		$showtime=$stime."到".$etime;
		if(trim($showtime)=='-')
			$showtime="全部";
		if($btcid!='-1')
		{
			$where=" and btcid='$btcid'";
			$strstr="{$btcid}号ACS";
		}
		$sql="select count(*) num from localhash_1 where uptime>='$stime' and uptime<='$etime'$where";
		//print $sql;
		$query=$dsid->query($sql);
		$cnum=$dsid->fetch_array($query);

		$sql="select count(*) num from localhash_1 where uptime>='$stime' and uptime<='$etime'and completed='1'$where";
		//print $sql;
		$query=$dsid->query($sql);
		$cnumc=$dsid->fetch_array($query);
		//print_r($cnum);
		//print_r($showtime);
		/*
		while ($ipl = $dp->fetch_array($iptablequery))
		{
			$iptables++;
		}
		$infos['totalip']=$iptables;
		//$infos['totalip']=$count['count(*)'];//IP访问总数
		$infos['totalpage']=$count['count(*)'];//推送页面显示次数
		
		$allpage=ceil($count['count(*)']/$limit);
		
		$page=$page>$allpage?$allpage:$page;
		$url='count.inc.php?action='.$action.'&amp;stime='.$stime.'&amp;etime='.$etime.'&amp;webname='.$webname.'&amp;';
		$pages=numofpage($count['count(*)'],$page,$allpage,$url);
	
	
		$ipclist=array();	
		$sql="select * from  ps_count where ctime>='$stime' and ctime<='$etime' ".$where."  order by cid desc limit $start,$limit";
		$query=$dp->query($sql);
		$ipdb = array();
		while($list=$dp->fetch_array($query))
		{
			$list['ctime']=date('Y-m-d H:i:s',$list['ctime']);
			$list['web']=$warray[$list['dwebsite']];
			$iplist[]=$list;
			$ipdb[] = $list['cip'];
		}
		//下载统计
		
		$downlist=array();	
		//$sql="select cip as dip from  ps_count where ctime>='$stime' and ctime<='$etime' ".$where."  group by cip limit $start,$limit";
		$original=0;
		$digest=0;
		$ipdb=array_unique($ipdb);
		foreach($ipdb as $lp)
		{
			//原始
			$dipsql="select count(*) from ps_down where dtime>='$stime' and dtime<='$etime' and dip='$lp' and  dtype='1'$where";
			
			$dipq=$dp->query($dipsql);
			$count=$dp->fetch_array($dipq);
			$list['count1']=$count['count(*)'];//单个IP下载原始资源次数
			$original+=$count['count(*)'];
			
			//推荐
			$dipsql="select count(*) from ps_down where dtime>='$stime' and dtime<='$etime' and dip='$lp' and  dtype='0' $where";
			$dipq=$dp->query($dipsql);
			$count=$dp->fetch_array($dipq);
			$list['count2']=$count['count(*)'];//单个IP下载推荐资源次数
			$digest+=$count['count(*)'];
			
			$list['count3']=$list['count1']+$list['count2'];//单个IP访问总次数
			$list['dip']=$lp;
			
			//访问总次数
		
			$cipsql="select count(*) from ps_count where ctime>='$stime' and ctime<='$etime' and cip='$lp' $where";
	
			$cipq=$dp->query($cipsql);
			$count=$dp->fetch_array($cipq);
			$list['count4']=$count['count(*)'];
			$downlist[]=$list;
			
		}
		$infos['digest']=$digest;//下载推荐种子次数
		$infos['original']=$original;//下载原始种子次数
		$infos['downs']=$ysys+$tjtj;
		//$infos['downs']=$original+$digest;
	$infos['dpercent']=round($infos['digest']/$infos['downs'],4)*100;//下载推荐种子次数/总下载次数   
	$infos['opercent']=round($infos['original']/$infos['downs'],4)*100;//下载原始种子次数/总下载次数
	$infos['percent']=round($infos['downs']/$infos['totalpage'],4)*100;//总下载次数/总显示次数
		//---------------------------
		$infos['fdpercent']=ceil(($infos['digest']/$infos['downs'])*100)*3;//下载推荐种子次数/总下载次数   
		$infos['fopercent']=ceil(($infos['original']/$infos['downs'])*100)*3;//下载原始种子次数/总下载次数
		$infos['fpercent']=ceil(($infos['downs']/$infos['totalpage'])*100)*3;//总下载次数/总显示次数
		if($infos['fpercent']>300)
		{
			$infos['fpercent'] = 300;
		}
		//----------------------------
		$winfos=array();
		$webinfos='';
		for($i=0;$i<count($warray);$i++)
		{
			$sql="select count(*) from ps_count where ctime>='$stime' and ctime<='$etime' and dwebsite='$i'";
			//print $sql;
			$wsql=$dp->query($sql);
			$wcount=$dp->fetch_array($wsql);
			$key=$warray[$i];
			$winfos[$key]=$wcount['count(*)'];//做为保留功能
			if($key=='')
				$key='其他';
			$webinfos.=$key.':'.$wcount['count(*)'].'次&nbsp;&nbsp;&nbsp;';
		}*/
	}
	
	include_once MCC_ROOT.'/templates/msystem/count.htm';
}
function GmtToUnix($GmtDate)
{
 $DateArr = explode(' ',$GmtDate); // 分割GMT日期为 日期 | 时间

 /* 在日期中取得年,月,日 */
 $pDate = split('[/.-]',$DateArr[0]);
 $Year = $pDate[0];
 $Month = $pDate[1];
 $Day = $pDate[2];
 
 /* 在时间中取得时,分,秒 */
 $pTime = split('[:.-]',$DateArr[1]);
 $Hour = $pTime[0];
 $Minute = $pTime[1];
 $Second = $pTime[2];
 
 if($Year == '' || !is_numeric($Year))$Year = 0;
 if($Month == '' || !is_numeric($Month))$Month = 0;
 if($Day == '' || !is_numeric($Day))$Day = 0;
 if($Hour == '' || !is_numeric($Hour))$Hour = 0;
 if($Minute == '' || !is_numeric($Minute))$Minute = 0;
 if($Second == '' || !is_numeric($Second))$Second = 0;
 return mktime($Hour,$Minute,$Second,$Month,$Day,$Year);
}
?>
